#include "heard.h"


int init_socket(int *sock_fd, char *ip, char *port){
    printf("port:%s, ip:%s\n",port,ip);
    *sock_fd = socket(AF_INET, SOCK_STREAM, 0);
    struct sockaddr_in addr;
    addr.sin_family = AF_INET;
    addr.sin_port = htonl(atoi(port));

    addr.sin_addr.s_addr = inet_addr(ip);

    if(bind(*sock_fd, (struct sockaddr*)&addr, sizeof(addr)) != 0){

        error(1,errno,"bind fail");
    }
    if(listen(*sock_fd, 10) != 0){

        error(1,errno, "listen fail");
    }
    return 0;
}
